/**
 iTextUploader
 (C) 2008 MyselftDev (myselftdev@gmail.com)
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; version 2
 of the License.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

/* Revision: $Id: AlertBox.m 59 2009-01-29 20:25:29Z myselftdev $ */

#import "AlertBox.h"

@implementation AlertBox

@synthesize activityIndicator;
@synthesize alertView;

- (id)initAlertBox
{
	CGRect viewRect = CGRectMake(30.0, 200.0, 250.0, 70.0);
	CGRect indicatorRect = CGRectMake(120.0, 10.0, 20.0, 20.0);
	CGRect textRect = CGRectMake(0.0, 30.0, 260.0, 40.0);
	
	if((self = [super initWithFrame:[[UIScreen mainScreen] bounds]]))
	{
		self.windowLevel = UIWindowLevelAlert;
		[self makeKeyAndVisible];
		
		alertView = [ [UIView alloc] initWithFrame:viewRect];
		alertView.backgroundColor = [UIColor clearColor];
		[self addSubview:alertView];
		
		text = [ [NSString alloc] initWithString:@"Loading..."];
		
		UIImage *baseImage = [ [UIImage imageNamed:@"loading_bg.png"] stretchableImageWithLeftCapWidth:20.0 topCapHeight:20.0];
		backgroundView = [ [UIImageView alloc] initWithImage:baseImage];
		backgroundView.frame = alertView.bounds;
		[alertView addSubview:backgroundView];
		
		textView = [ [UITextView alloc] initWithFrame:textRect];
		textView.text = text;
		textView.textAlignment = UITextAlignmentCenter;
		textView.font = [UIFont systemFontOfSize:18.0];
		textView.textColor = [UIColor whiteColor];
		textView.backgroundColor = [UIColor clearColor];
		textView.editable = NO;
		textView.scrollEnabled = NO;
		[alertView addSubview:textView];
				
		activityIndicator = [ [UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
		[activityIndicator startAnimating];
		activityIndicator.frame = indicatorRect;
		[alertView addSubview:activityIndicator];
	}
	
	return self;
}

- (void)setText:(NSString *)newText
{
	if(newText != text)
	{
		[text release];
		text = [newText retain];
		textView.text = text;
	}
}

- (NSString*)text
{
	return text;
}

- (void)setHidden: (BOOL)newVal
{
	[self makeKeyWindow];
	[super setHidden:newVal];
}

- (void)dealloc
{
	[alertView release];
	[activityIndicator release];
	[backgroundView release];
	[textView release];
	[text release];
	
    [super dealloc];
}


@end
